<?php

namespace App\Http\Controllers\Home;

use App\Http\Controllers\Controller;
use App\Models\Diocese;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;

class DioceseController extends Controller
{
    //
    public function getlist(Request $request){
        $model = Diocese::has('cathedral');
        $province_adcode = $request->input('province_adcode');
        if($province_adcode){
            $model->where('province_adcode',$province_adcode);
        }
        $list = $model->get();
        $list->load('cathedral');
        return new ResourceCollection($list);
    }

    public function getListHasParish(Request $request){
        $model = Diocese::has('parishlist','>',1)->select('id','title');
        $province_adcode = $request->input('province_adcode');
        if($province_adcode){
            $model->where('province_adcode',$province_adcode);
        }
        $parishlist = $model->get();
        $parishlist->load('parishlist');
        // foreach($parishlist as $parish){
        //     foreach($parish->parishlist as $par){
        //         $par->position;
        //         // $par->load('position');
        //     }
        // }
        // dump($parishlist->toArray());
        return $parishlist;
    }
}
